package com.xjy.web.controller.system;

import com.xjy.common.annotation.Log;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.core.domain.entity.SysUser;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.enums.BusinessType;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.system.domain.bo.SysCheckaccountAddBo;
import com.xjy.system.domain.bo.SysCheckaccountEditBo;
import com.xjy.system.domain.bo.SysCheckaccountPlungeBo;
import com.xjy.system.domain.bo.SysCheckaccountQueryBo;
import com.xjy.system.domain.vo.SysCheckaccountVo;
import com.xjy.system.domain.vo.SysFundaccountVo;
import com.xjy.system.service.ISysCheckaccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

import static com.xjy.common.utils.SecurityUtils.getLoginUser;

/**
 * 账户结账管理信息Controller
 *
 * @author xjy
 * @date 2022-03-18
 */
@Api(value = "账户结账管理信息控制器", tags = {"账户结账管理信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/checkaccount")
public class SysCheckaccountController extends BaseController {

	private final ISysCheckaccountService iSysCheckaccountService;

	/**
	 * 查询账户结账管理信息列表
	 */
	@ApiOperation("查询账户结账管理信息列表")
	@PreAuthorize("@ss.hasPermi('system:checkaccount:list')")
	@GetMapping("/list")
	public TableDataInfo<SysCheckaccountVo> list(@Validated SysCheckaccountQueryBo bo) {
		return iSysCheckaccountService.queryPageList(bo);
	}

	/**
	 * 导出账户结账管理信息列表
	 */
	@ApiOperation("导出账户结账管理信息列表")
	@PreAuthorize("@ss.hasPermi('system:checkaccount:export')")
	@Log(title = "账户结账管理信息", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<SysCheckaccountVo> export(@Validated SysCheckaccountQueryBo bo) {
		List<SysCheckaccountVo> list = iSysCheckaccountService.queryList(bo);
		ExcelUtil<SysCheckaccountVo> util = new ExcelUtil<SysCheckaccountVo>(SysCheckaccountVo.class);
		return util.exportExcel(list, "账户结账管理信息");
	}

	/**
	 * 获取账户结账管理信息详细信息
	 */
	@ApiOperation("获取账户结账管理信息详细信息")
	@PreAuthorize("@ss.hasPermi('system:checkaccount:query')")
	@GetMapping("/{id}")
	public AjaxResult<SysCheckaccountVo> getInfo(@NotNull(message = "主键不能为空")
												 @PathVariable("id") Long id) {
		return AjaxResult.success(iSysCheckaccountService.queryById(id));
	}

	/**
	 * 新增账户结账管理信息
	 */
	@ApiOperation("新增账户结账管理信息")
	@PreAuthorize("@ss.hasPermi('system:checkaccount:add')")
	@Log(title = "账户结账管理信息", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping()
	public AjaxResult<SysFundaccountVo> add(@Validated @RequestBody SysCheckaccountPlungeBo bo) {
		SysUser user = getLoginUser().getUser();
		bo.setManagerId(user.getUserId());
		bo.setManager(user.getUserName());
		AjaxResult<SysFundaccountVo> ajaxResult = new AjaxResult();
		ajaxResult.success(iSysCheckaccountService.insertByAddBo(bo));
		return ajaxResult;
	}

	/**
	 * 修改账户结账管理信息
	 */
	@ApiOperation("修改账户结账管理信息")
	@PreAuthorize("@ss.hasPermi('system:checkaccount:edit')")
	@Log(title = "账户结账管理信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping()
	public AjaxResult<SysFundaccountVo> edit(@Validated @RequestBody SysCheckaccountPlungeBo bo) {
		AjaxResult<SysFundaccountVo> ajaxResult = new AjaxResult();
		ajaxResult.success(iSysCheckaccountService.updateByEditBo(bo));
		return ajaxResult;
	}

	/**
	 * 修改账户结账管理信息
	 */
	@ApiOperation("扎帐判断")
	@PreAuthorize("@ss.hasPermi('system:checkaccount:edit')")
	@Log(title = "账户结账管理信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PostMapping("/plunge")
	public List<SysFundaccountVo> plunge(@Validated @RequestBody SysCheckaccountPlungeBo bo) {
		return iSysCheckaccountService.plunge(bo);
	}


	/**
	 * 删除账户结账管理信息
	 */
	@ApiOperation("删除账户结账管理信息")
	@PreAuthorize("@ss.hasPermi('system:checkaccount:remove')")
	@Log(title = "账户结账管理信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iSysCheckaccountService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
